
#include "testFiles.h"

CPPUNIT_TEST_SUITE_REGISTRATION (testFiles);

void testFiles :: setUp (void){
}

void testFiles :: tearDown (void) {
	if(file) delete file;
}

void testFiles :: addContentIntoFile (void)
{
	file = new files("res/existsfile","w");
	CPPUNIT_ASSERT_EQUAL (file->putContent("TestContent"), true);
}

void testFiles :: readContentFromFile(void)
{
	file = new files("res/existsfile","r");
	CPPUNIT_ASSERT_EQUAL (file->getContent(), (string)"TestContent");
}


void testFiles :: checkForExistingFile (void)
{
	file = new files("res/existsfile","r");
	CPPUNIT_ASSERT_EQUAL (file->isFile(), true);
}

void testFiles :: checkForExistingFileWithNoFile (void)
{
	file = new files("res/noexistsfile","r");
	CPPUNIT_ASSERT_EQUAL (file->isFile(), false);
}

void testFiles :: exceptionTestForNoExistsFile (void)
{
	file = new files("res/noexistsfile","r");
	CPPUNIT_ASSERT_THROW (file->getContent(), noFileExists);
}

void testFiles :: testDeleteFileFromDisk() {
	file = new files("res/fileToDelete","w");
	file->putContent("1");
	delete file;

	file = new files("res/fileToDelete","");
	CPPUNIT_ASSERT_EQUAL (true, file->isFile());
	delete file;

	file = new files("res/fileToDelete","");
	file->erase();
	delete file;

	file = new files("res/fileToDelete","r");
	CPPUNIT_ASSERT_EQUAL (false, file->isFile());
}
